home *** CD-ROM | disk | FTP | other *** search
/ IRIX Base Documentation 2001 May / SGI IRIX Base Documentation 2001 May.iso / usr / share / catman / p_man / cat5 / varargs.z / varargs
Encoding:
Text File  |  1998-10-30  |  5.5 KB  |  133 lines

  1.  
  2.  
  3.  
  4. VVVVAAAARRRRAAAARRRRGGGGSSSS((((5555))))                                                          VVVVAAAARRRRAAAARRRRGGGGSSSS((((5555))))
  5.  
  6.  
  7.  
  8. NNNNAAAAMMMMEEEE
  9.      varargs - variable argument list
  10.  
  11. SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.      ####iiiinnnncccclllluuuuddddeeee <<<<vvvvaaaarrrraaaarrrrggggssss....hhhh>>>>
  13.  
  14.      _f_u_n_c_t_i_o_n(vvvvaaaa____aaaalllliiiisssstttt)
  15.      vvvvaaaa____ddddccccllll
  16.      vvvvaaaa____lllliiiisssstttt _p_v_a_r;
  17.      vvvvaaaa____ssssttttaaaarrrrtttt(_p_v_a_r);
  18.      f = vvvvaaaa____aaaarrrrgggg(_p_v_a_r, _t_y_p_e);
  19.      vvvvaaaa____eeeennnndddd(_p_v_a_r);
  20.  
  21. DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  22.      This set of macros provides a means of writing portable procedures that
  23.      accept variable argument lists.  Routines having variable argument lists
  24.      (such as _p_r_i_n_t_f(3)) that do not use varargs are inherently nonportable,
  25.      since different machines use different argument passing conventions.
  26.  
  27.      PLEASE NOTE: varargs is being supplanted by stdarg(5). Users should
  28.      reference that man page for the recommended method of passing variable
  29.      argument lists.
  30.  
  31.      vvvvaaaa____aaaalllliiiisssstttt is used in a function header to declare a variable argument
  32.      list.
  33.  
  34.      vvvvaaaa____ddddccccllll is a declaration for vvvvaaaa____aaaalllliiiisssstttt.  Note that there is no semicolon
  35.      after vvvvaaaa____ddddccccllll....
  36.  
  37.      vvvvaaaa____lllliiiisssstttt is a type which can be used for the variable _p_v_a_r, which is used
  38.      to traverse the list.  One such variable must always be declared.
  39.  
  40.      vvvvaaaa____ssssttttaaaarrrrtttt(pvar) is called to initialize _p_v_a_r to the beginning of the list.
  41.  
  42.      vvvvaaaa____aaaarrrrgggg(_p_v_a_r, _t_y_p_e) will return the next argument in the list pointed to
  43.      by _p_v_a_r.  _T_y_p_e is the type to which the expected argument will be
  44.      converted when passed as an argument.  In standard C, arguments that are
  45.      cccchhhhaaaarrrr or sssshhhhoooorrrrtttt should be accessed as iiiinnnntttt, uuuunnnnssssiiiiggggnnnneeeedddd cccchhhhaaaarrrr or uuuunnnnssssiiiiggggnnnneeeedddd sssshhhhoooorrrrtttt
  46.      are converted to uuuunnnnssssiiiiggggnnnneeeedddd iiiinnnntttt, and ffffllllooooaaaatttt arguments are converted to
  47.      ddddoooouuuubbbblllleeee.  Different types can be mixed, but it is up to the routine to
  48.      know what type of argument is expected, since it cannot be determined at
  49.      runtime.
  50.  
  51.      vvvvaaaa____eeeennnndddd(_p_v_a_r) is used to finish up.
  52.  
  53.      Multiple traversals, each bracketed by vvvvaaaa____ssssttttaaaarrrrtttt ...  vvvvaaaa____eeeennnndddd,,,, are
  54.      possible.
  55.  
  56. EEEEXXXXAAAAMMMMPPPPLLLLEEEE
  57.           ####iiiinnnncccclllluuuuddddeeee <varargs.h>
  58.           execl(vvvvaaaa____aaaalllliiiisssstttt)
  59.           vvvvaaaa____ddddccccllll
  60.  
  61.  
  62.  
  63.                                                                         PPPPaaaaggggeeee 1111
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70. VVVVAAAARRRRAAAARRRRGGGGSSSS((((5555))))                                                          VVVVAAAARRRRAAAARRRRGGGGSSSS((((5555))))
  71.  
  72.  
  73.  
  74.          {
  75.                vvvvaaaa____lllliiiisssstttt ap;
  76.                cccchhhhaaaarrrr *file;
  77.                cccchhhhaaaarrrr *args[100];
  78.                iiiinnnntttt argno = 0;
  79.  
  80.                vvvvaaaa____ssssttttaaaarrrrtttt(ap);
  81.                file = vvvvaaaa____aaaarrrrgggg(ap, cccchhhhaaaarrrr *);
  82.                wwwwhhhhiiiilllleeee (args[argno++] = vvvvaaaa____aaaarrrrgggg(ap, cccchhhhaaaarrrr *))
  83.                     ;;;;
  84.                vvvvaaaa____eeeennnndddd(ap);
  85.                rrrreeeettttuuuurrrrnnnn execv(file, args);
  86.           }
  87.  
  88. SSSSEEEEEEEE AAAALLLLSSSSOOOO
  89.      stdarg(5)
  90.  
  91. BBBBUUUUGGGGSSSS
  92.      It is up to the calling routine to determine how many arguments there
  93.      are, since it is not possible to determine this from the stack frame.
  94.      For example, _e_x_e_c_l passes a 0 to signal the end of the list.  _P_r_i_n_t_f can
  95.      tell how many arguments are supposed to be there by the format.
  96.  
  97.      The macros _v_a__s_t_a_r_t and _v_a__e_n_d may be arbitrarily complex; for example,
  98.      _v_a__s_t_a_r_t might contain an opening brace, which is closed by a matching
  99.      brace in _v_a__e_n_d.  Thus, they should only be used where they could be
  100.      placed within a single complex statement.
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.                                                                         PPPPaaaaggggeeee 2222
  130.  
  131.  
  132.  
  133.